<template>
  <div class="content_box">
    <div class="list_box" v-if="list.length">
      <div :class="item.status != 0?'box on':'box'" v-for="(item,index) in list" :key="index">
        <img class="bj" src="/static/images/coupon_bj.png" alt="">
        <p class="label" v-if="item.couponType == 1">折扣券</p>
        <p class="label" v-if="item.couponType == 0">指定金额</p>
        <p class="label" v-if="item.couponType == 2">满减券</p>
        <div class="nr">
          <div class="left">
            <p class="price" v-if="item.couponType == 1">{{item.discount}}<span>折</span></p>
            <p class="price" v-if="item.couponType == 0"><span>￥</span>{{item.amount}}</p>
            <p class="price" v-if="item.couponType == 2"><span>￥</span>{{item.subtract}}</p>
            <p class="text">{{item.content}}</p>
          </div>
          <p class="line"></p>
          <div class="right">
            <div class="name_box">
              <div class="name">
                <p class="title" v-if="item.couponType == 1">折扣券</p>
                <p class="title" v-if="item.couponType == 0">指定金额</p>
                <p class="title" v-if="item.couponType == 2">满减券</p>
                <p class="time">有效期至{{item.endTime}}</p>
              </div>
              <p class="anniu" v-if="item.status == 0" @click="toHome">去使用</p>
              <img v-else-if="item.status == 1" src="/static/images/stamp1.png" alt="">
              <img v-else src="/static/images/stamp2.png" alt="">
            </div>
            <p class="jiesao">{{item.remark}}</p>
          </div>
        </div>
      </div>
      <p class="nodata">暂无更多优惠券</p>
    </div>
    <div class="no_data1" v-else>
      <img mode="widthFix" src="/static/images/components/no_yh.png" alt="" />
      <p class="text">暂无优惠券</p>
   </div>
  </div>
</template>

<script>
import { 
  getUserCouponPage,
} from "@/api/index";
export default {
  data(){
    return{
      query:{
        current:1,
        size:10
      },
      list:[],
      active: 0,
    }
  },
  methods:{

    // 去使用跳转首页
    toHome(){
      wx.switchTab({
        url:'/pages/home/main'
      })
    },

    // 获取优惠券列表
    getList(state){
      this.$showLoading('加载中...')
      getUserCouponPage(this.query).then(res=>{
        if(res.statusCode == '00000'){
          if(this.query.current != 1 && !res.data.records.length){
            wx.showToast({
              title: '已经到底了~',
              icon: 'none',
              duration: 1500
            })
            return
          }
          if(state){
            this.list = []
          }
          res.data.records.map(item=>{
            item.startTime = item.startTime.substring(0,10);
            item.endTime = item.endTime.substring(0,10);
          })
          this.list = this.list.concat(res.data.records)
          wx.hideLoading()
          wx.hideNavigationBarLoading();
          wx.stopPullDownRefresh();
        }else{
          wx.hideLoading()
          wx.hideNavigationBarLoading();
          wx.stopPullDownRefresh();
        }
      })
    }
  },
  // 下拉刷新
  onPullDownRefresh(){
    wx.showLoading({
        title: '加载中...'
    })
    //在当前页面显示导航条加载动画
    wx.showNavigationBarLoading();
    //显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框
    setTimeout(()=>{
        this.getList(true)
    },500)
  },
  // 上拉加载
 onReachBottom(){
   //console.log('到底了')
   this.query.current += 1
   this.getList()
 },
  onLoad(options){
    this.getList(true)
  }
}
</script>

<style lang="scss" scoped>
.content_box{
  background: #F8F9FA;
  min-height: 100vh;
  .list_box{
    padding-top: 24rpx;
    .box{
      width: 92%;
      height: 208rpx;
      position: relative;
      margin:0 auto;
      margin-bottom:24rpx;
      .bj{
        width: 100%;
        height: 100%;
        position: absolute;
        top:0;
        left:0;
        z-index: 10;
      }
      .bj1{
        width: 100%;
        height: 100%;
        position: absolute;
        top:15rpx;
        left:0;
        z-index: 1;
      }
      .label{
        position: absolute;
        top:0;
        left: 6rpx ;
        padding:0 16rpx;
        height: 40rpx;
        background: linear-gradient(to right,#FF4357, #FE6E34);
        z-index: 20;
        font-size:22rpx;
        color:#fff;
        display: flex;
        align-items: center;
        justify-content: center;
        border-top-left-radius: 16rpx;
        border-bottom-right-radius: 16rpx;
        font-weight: 500;
      }
      .nr{
        position: relative;
        z-index: 30;
        display: flex;
        .left{
          width: 29%;
          height: 208rpx;
          display: flex;
          flex-direction:column;
          justify-content: center;
          align-items: center;
          .price{
            display: flex;
            align-items: baseline;
            font-size:70rpx;
            font-weight: bold;
            color:#FF4622;
            span{
              font-size:30rpx;
            }
          }
          .text{
            font-size:24rpx;
            color:#696B6E;
          }
        }  
        .line{
          width: 1rpx;
          height: 160rpx;
          border-right:1px dashed #E4E4E4;
          margin-top:22rpx;
        }
        .right{
          flex: 1;
          padding-left:24rpx;
          .name_box{
            display: flex;
            justify-content: space-between;
            align-items: flex-end;
            margin-top:30rpx;
            margin-bottom:28rpx;
            .name{
              .title{
                color:#242526;
                font-size:32rpx;
                font-weight: 500;
                margin-bottom:12rpx;
              }
              .time{
                color:#666666;
                font-size:24rpx;
              }
            }
            img{
              width: 124rpx;
              height: 124rpx;
              position: absolute;
              right: 6rpx;
              top:8rpx;
            }
            .anniu{
              width: 114rpx;
              height: 50rpx;
              background: linear-gradient(to right,#FF4357, #FE6E34);
              font-size:24rpx;
              color:#fff;
              font-weight: bold;
              border-radius: 50rpx;
              display: flex;
              align-items: center;
              justify-content: center;
              margin-right:22rpx;
            }
          }
          .jiesao{
            color:#999999;
            font-size:22rpx;
          }
        }      
      }
      &.on{
        .label{
          color:#383838;
          background: #F6F6F8 ;
        }
        .price{
          color:#AEAFB0 !important;
        }
        .text{
          color:#B0B1B4 !important ;
        }
        .title{
          color:#8D8E90 !important;
        }
        .time{
          color:#AEAFB0 !important ;
        }
        .jiesao{
          color:#C8C8CA !important;
        }
      }
    }
  }
  .nodata{
    text-align: center;
    color:rgb(119, 118, 118);
    font-size:26rpx;
    margin-top:50rpx
  }
  .no_data1{
    text-align: center;
    font-size:28rpx;
    color:#333;
    padding-top:150rpx;
    .text{
      font-weight: 500;
      color:#999;
    }
    img{
      width: 248rpx;
      margin-bottom:10rpx;
    }
  }
}
</style>